package com.six.core.controller;

import com.six.core.entity.Area;
import com.six.core.entity.Emp;
import com.six.core.service.AreaService;
import com.six.core.vo.AreaVo;
import com.six.core.vo.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

import java.security.PublicKey;

/**
 * @Description:
 * @author:LiWei
 * @date:2023年02月28日9:07
 */
@Api(value = "/area/area", tags = {":"})
@RequestMapping("/area/area")
@RestController
public class AreaController {

    @Autowired
    private AreaService areaService;
    @Autowired
    private RedisTemplate redisTemplate;

    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", dataType = "int", name = "currentPage", value = "", required = true),
            @ApiImplicitParam(paramType = "path", dataType = "int", name = "pageSize", value = "", required = true),
            @ApiImplicitParam(paramType = "body", dataType = "AreaVo", name = "areaVo", value = "", required = true)
    })
    @ApiOperation(value = "", notes = "")
    @RequestMapping("list/{currentPage}/{pageSize}")
    public Result list(@PathVariable Integer currentPage, @PathVariable Integer pageSize, @RequestBody AreaVo areaVo){
        Result all = areaService.findAll(currentPage,pageSize,areaVo);
        return new Result(200,"查询成功",all);
    }

    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", dataType = "Area", name = "area", value = "", required = true)
    })
    @ApiOperation(value = "", notes = "")
    @RequestMapping("addArea")
    public Result addArea(@RequestBody Area area){
        return areaService.addArea(area);

    }

    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", dataType = "Area", name = "area", value = "", required = true)
    })
    @ApiOperation(value = "", notes = "")
    @RequestMapping("updateArea")
    public Result updateArea(@RequestBody Area area){
        return areaService.updateArea(area);

    }

    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "int", name = "id", value = "", required = true)
    })
    @ApiOperation(value = "", notes = "")
    @RequestMapping("deleteById/{id}")
    public Result deleteById(@PathVariable Integer id){
        return areaService.deleteById(id);
    }

    //显示所有管理员
    @ApiOperation(value = "显示所有管理员", notes = "显示所有管理员")
    @RequestMapping("findAllEmp")
    public Result findAllEmp(){
        return areaService.findAllEmp();
    }

    //判断该区域是否有管理员
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", dataType = "string", name = "id", value = "", required = true)
    })
    @ApiOperation(value = "判断该区域是否有管理员", notes = "判断该区域是否有管理员")
    @RequestMapping("/exitEmp/{id}")
    public Result exitEmp(@PathVariable Integer id){
        return areaService.exitEmp(id);
    }
    //确认分配管理员
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", dataType = "int", name = "areaid", value = "", required = true),
            @ApiImplicitParam(paramType = "body", dataType = "Emp", name = "emp", value = "", required = true)
    })
    @ApiOperation(value = "确认分配管理员", notes = "确认分配管理员", httpMethod = "POST")
    @PostMapping("/confirmEmp/{areaid}")
    public Result confirmEmp(@PathVariable Integer areaid,@RequestBody Emp emp){
        return areaService.confirmEmp(areaid,emp);
    }

    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", dataType = "int", name = "id", value = "", required = false)
    })
    @ApiOperation(value = "", notes = "", httpMethod = "POST")
    @PostMapping("/findEmp/{id}")
    public Result findEmp(@PathVariable Integer id){
        return areaService.findEmp(id);
    }

    @GetMapping("/findAllArea")
    public Result findAllArea(){
        return areaService.findAllArea();
    }
}
